﻿NAMFox.ns(function() { with (NAMFox) {

name("Data Repository Tests");

//////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////

var key = new Date().toString();

//////////////////////////////////////////////
// Test Cases
//////////////////////////////////////////////

test("All data keys have default data", function() {
    for (var i in $.dataKeys) {
        if ($.dataKeys.hasOwnProperty(i)) {
            ok($.dataRepository.getData($.dataKeys[i]), "The data repository must have truthy data for the data key '" + $.dataKeys[i] + "'.");
            ok(typeof($.dataRepository.getData($.dataKeys[i])) === "object", "The data repository must contain an object for the data key '" + $.dataKeys[i] + "'.");
        }
    }
});

test("DataRepository.getData returns null when the key is not present", function() {
    var data = $.dataRepository.getData(key);
    strictEqual(null, data, "The data returned for a key that doesn't exist must be null.");
});

test("DataRepository.getData can retrieve any data", function() {
    $.dataRepository.setData(key, { check: "me" });
    var data = $.dataRepository.getData(key);

    equals("me", data.check, "Data added to the data repository must be retrievable.");
});

test("Setting null or undefined deletes data key", function() {
    $.dataRepository.setData(key, null);
    var data = $.dataRepository.getData(key);
    strictEqual(null, data, "Setting a key's data to null must delete the key.");

    $.dataRepository.setData(key, undefined);
    data = $.dataRepository.getData(key);
    strictEqual(null, data, "Setting a key's data to undefined must delete the key.");
});

}});